import {
  BaseEntity,
  BaseService,
  DatabaseManager, FieldFill,
  IdGenerationStrategy, LogicalDelete, MigrationUtil,
  Service,
  Table,
  TableField,
  TableId
} from "../src";

export const dbM = DatabaseManager.getInstance({
  dbPath: 'D:\\ATestQuicklite\\test.db',
  primaryKeyConfig: {
    idGenerationStrategy: IdGenerationStrategy.SNOWFLAKE
  },
  enableEncryption: true,
  password: '123456'
})

dbM.fieldFiller.register('createTime', {
  fillInsert(): any {
    return new Date().toISOString();
  }
})

@Table('book')
export class Book extends BaseEntity {

  @TableId()
  id!: number;

  @TableField()
  name!: string;

  @TableField()
  author!: string;

  @FieldFill()
  @TableField()
  createTime!: Date

  @LogicalDelete()
  deleted!: string
}

@Service(Book)
class BookService extends BaseService<Book> {

  findByName(name: string) {
    return this.find({
      where: {
        name
      }
    })
  }
}

// MigrationUtil.migrateTable(dbM.getDatabase(), Book, true)

console.log(Book.getTableInfo())

dbM.initializer.initTables()

const bookService = new BookService();
bookService.insert({
  name: '123'
})
const books = bookService.findByName('123')
console.log(books)
